﻿using MCPlatform.MotionLib.Base.Models;
using MCPlatform.MotionLib.Base;
using MCPlatform.UI.Controls.Models;
using Panuon.WPF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace MCPlatform.Models
{
    public class CoordinateModel : NotifyPropertyChangedBase
    {
        #region Properties
        public IImputation? ImputationEntity
        {
            get => _ImputationEntity;
            set { Set(ref _ImputationEntity, value); Initial(); }
        }
        private IImputation? _ImputationEntity;
        public ImpMotionModel ImpMotionModel { get => _ImpMotionModel; set => Set(ref _ImpMotionModel, value); }
        private ImpMotionModel _ImpMotionModel = new ImpMotionModel();

        public ImpMotionParaModel ImpMotionParaModel { get => _ImpMotionParaModel; set => Set(ref _ImpMotionParaModel, value); }
        private ImpMotionParaModel _ImpMotionParaModel = new ImpMotionParaModel();

        #endregion

        #region Methods

        Timer timer;
        public void StartMappingEntityToModel()
        {
            if (ImputationEntity is null)
            {
                return;
            }

            timer.Start();


        }


        public void StopMappingEntityToModel()
        {

            timer.Stop();


        }

        #endregion

        #region CTOR

        public CoordinateModel()
        {
            timer = new Timer(200);
            timer.Elapsed += Timer_Elapsed;


        }


        private void Timer_Elapsed(object? sender, ElapsedEventArgs e)
        {

            ImpMotionParaModel.CrdEntity = ImputationEntity;
            ImpMotionModel.ImputationEntity = ImputationEntity;

            ImpMotionModel.Mapping();


        }

        public void Initial()
        {
            ImpMotionParaModel.CrdEntity = ImputationEntity;
            ImpMotionModel.ImputationEntity = ImputationEntity;
        }
        #endregion
    }
}
